//-----------------------------------------------------------------------------
// SpriteBatch.fx
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


// Input parameters.
Texture  sprite;
float2   ViewportSize;
float2   TextureSize;
float4x4 MatrixTransform;

sampler2D  TextureSampler = sampler_state { 
	texture = <sprite>; 
	magfilter = LINEAR; 
	minfilter = LINEAR; 
	mipfilter = LINEAR; 
	AddressU = mirror; 
	AddressV = mirror;
	};

void SpriteVertexShader(inout float4 position : POSITION0,
		  				inout float4 color    : COLOR0,
						inout float2 texCoord : TEXCOORD0)
{
	// Half pixel offset for correct texel centering.
	position.xy -= 0.5;

	// Viewport adjustment.
	position.xy /= ViewportSize;
	position.xy *= float2(2, -2);
	position.xy -= float2(1, -1);

	//// Compute the texture coordinate.
	//texCoord /= TextureSize;
}


// Pixel shader for rendering sprites (shared between Windows and Xbox).
float4 SpritePixelShader(float4 vertexColor : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
	float4 color = vertexColor;
	color *= tex2D(TextureSampler, texCoord);
	return color;
}


technique SpriteBatch
{
	pass
	{
		AlphaBlendEnable	= true;
		SrcBlend			= SrcAlpha;
		DestBlend			= InvSrcAlpha;

		VertexShader = compile vs_1_1 SpriteVertexShader();
		PixelShader  = compile ps_2_0 SpritePixelShader();
	}
}
